package com.example;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class DemoService {
	@Autowired
	MongoTemplate mongoTemplate;
	
	@Resource
    private RedisTemplate<String,String> redisTemplate;

	@Cacheable( value = "usercache",keyGenerator = "simplekeyGenerator") //value = "usercache",
	public SpotMedia findMedia() {
		System.out.println("无缓存的时候调用这里");
		Query query = new Query(Criteria.where("typeId").is(2)).skip(2 * 1)
				.limit(2);
		SpotMedia media = mongoTemplate.findOne(query, SpotMedia.class);
		return media;
	}
}
